<!DOCTYPE HTML>
<html lang="zh-CN">




<head>
    <meta charset="utf-8">
    <meta name="keywords" content="JavaNote_Spring_Day03, 深度学习 故障诊断 Java">
    <meta name="description" content="河海大学 | 计算机与信息学院 | 信号与信息处理">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <!-- Global site tag (gtag.js) - Google Analytics -->


    <title>JavaNote_Spring_Day03 | 世庆的博客</title>
    <link rel="icon" type="image/png" href="/shiqing/favicon.png">

    <link rel="stylesheet" type="text/css" href="/shiqing/libs/awesome/css/all.css">
    <link rel="stylesheet" type="text/css" href="/shiqing/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/shiqing/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/shiqing/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/shiqing/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/shiqing/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/shiqing/css/my.css">

    <script src="/shiqing/libs/jquery/jquery.min.js"></script>

    <script src="https://sdk.jinrishici.com/v2/browser/jinrishici.js" charset="utf-8"></script>
<meta name="generator" content="Hexo 6.3.0"></head>




    <body>
        <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/shiqing/" class="waves-effect waves-light">
                    
                    <img src="/shiqing/medias/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">世庆的博客</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/shiqing/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>首页</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/shiqing/tags" class="waves-effect waves-light">
      
      <i class="fas fa-tags" style="zoom: 0.6;"></i>
      
      <span>标签</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/shiqing/categories" class="waves-effect waves-light">
      
      <i class="fas fa-bookmark" style="zoom: 0.6;"></i>
      
      <span>分类</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/shiqing/archives" class="waves-effect waves-light">
      
      <i class="fas fa-archive" style="zoom: 0.6;"></i>
      
      <span>归档</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/shiqing/about" class="waves-effect waves-light">
      
      <i class="fas fa-user-circle" style="zoom: 0.6;"></i>
      
      <span>关于</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/shiqing/contact" class="waves-effect waves-light">
      
      <i class="fas fa-comments" style="zoom: 0.6;"></i>
      
      <span>留言板</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/shiqing/friends" class="waves-effect waves-light">
      
      <i class="fas fa-address-book" style="zoom: 0.6;"></i>
      
      <span>友情链接</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="搜索" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>


<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/shiqing/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">世庆的博客</div>
        <div class="logo-desc">
            
            河海大学 | 计算机与信息学院 | 信号与信息处理
            
        </div>
    </div>

    

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/shiqing/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			首页
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/shiqing/tags" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-tags"></i>
			
			标签
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/shiqing/categories" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-bookmark"></i>
			
			分类
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/shiqing/archives" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-archive"></i>
			
			归档
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/shiqing/about" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-user-circle"></i>
			
			关于
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/shiqing/contact" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-comments"></i>
			
			留言板
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/shiqing/friends" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-address-book"></i>
			
			友情链接
		</a>
          
        </li>
        
        
        <li><div class="divider"></div></li>
        <li>
            <a href="https://github.com/sqtian-hhu/" class="waves-effect waves-light" target="_blank">
                <i class="fab fa-github-square fa-fw"></i>Fork Me
            </a>
        </li>
        
    </ul>
</div>


        </div>

        
            <style>
    .nav-transparent .github-corner {
        display: none !important;
    }

    .github-corner {
        position: absolute;
        z-index: 10;
        top: 0;
        right: 0;
        border: 0;
        transform: scale(1.1);
    }

    .github-corner svg {
        color: #0f9d58;
        fill: #fff;
        height: 64px;
        width: 64px;
    }

    .github-corner:hover .octo-arm {
        animation: a 0.56s ease-in-out;
    }

    .github-corner .octo-arm {
        animation: none;
    }

    @keyframes a {
        0%,
        to {
            transform: rotate(0);
        }
        20%,
        60% {
            transform: rotate(-25deg);
        }
        40%,
        80% {
            transform: rotate(10deg);
        }
    }
</style>

<a href="https://github.com/sqtian-hhu/" class="github-corner tooltipped hide-on-med-and-down" target="_blank"
   data-tooltip="Fork Me" data-position="left" data-delay="50">
    <svg viewBox="0 0 250 250" aria-hidden="true">
        <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
        <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
              fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
        <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
              fill="currentColor" class="octo-body"></path>
    </svg>
</a>
        
    </nav>

</header>

        



<div class="bg-cover pd-header post-cover" style="background-image: url('/shiqing/medias/featureimages/16.jpg')">
    <div class="container" style="right: 0px;left: 0px;">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <h1 class="description center-align post-title">JavaNote_Spring_Day03</h1>
                </div>
            </div>
        </div>
    </div>
</div>




<main class="post-container content">

    
    <link rel="stylesheet" href="/shiqing/libs/tocbot/tocbot.css">
<style>
    #articleContent h1::before,
    #articleContent h2::before,
    #articleContent h3::before,
    #articleContent h4::before,
    #articleContent h5::before,
    #articleContent h6::before {
        display: block;
        content: " ";
        height: 100px;
        margin-top: -100px;
        visibility: hidden;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        width: 345px;
        padding-left: 20px;
    }

    .toc-widget .toc-title {
        padding: 35px 0 15px 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content {
        padding-bottom: 30px;
        overflow: auto;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;

        position: absolute;
        right: 23.5vw;
        display: block;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #floating-toc-btn {
        position: fixed;
        right: 15px;
        bottom: 76px;
        padding-top: 15px;
        margin-bottom: 0;
        z-index: 998;
    }

    #floating-toc-btn .btn-floating {
        width: 48px;
        height: 48px;
    }

    #floating-toc-btn .btn-floating i {
        line-height: 48px;
        font-size: 1.4rem;
    }
</style>
<div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/shiqing/tags/Java%E6%A1%86%E6%9E%B6/">
                                <span class="chip bg-color">Java框架</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fas fa-bookmark fa-fw icon-category"></i>
                        
                            <a href="/shiqing/categories/Java/" class="post-category">
                                Java
                            </a>
                        
                    </div>
                    
                </div>
            </div>

            <div class="post-info">
                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-minus fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2020-06-29
                </div>
                

                

                

                

                
            </div>
        </div>
        <hr class="clearfix">

        
        <!-- 是否加载使用自带的 prismjs. -->
        <link rel="stylesheet" href="/shiqing/libs/prism/prism.css">
        

        

        <div class="card-content article-card-content">
            <div id="articleContent">
                <h2 id="Day3"><a href="#Day3" class="headerlink" title="Day3"></a>Day3</h2><p>spring中的app和基于XML以及注解的AOP配置</p>
<ol>
<li><p>完善我们的account案例</p>
</li>
<li><p>分析案例中的问题</p>
</li>
<li><p>回顾之前讲过的一个技术: 动态代理</p>
</li>
<li><p>动态代理另一种实现方式</p>
</li>
<li><p>解决案例中的问题</p>
</li>
<li><p>AOP的概念</p>
</li>
<li><p>spring中的AOP相关术语</p>
</li>
<li><p>spring中基于XML和注解的AOP配置</p>
<pre><code> 编码问题，改成utf8
 &lt;property name=&quot;jdbcUrl&quot; value=&quot;jdbc:mysql://localhost:3306/lovelycc?characterEncoding=utf8&quot;&gt;&lt;/property&gt;
</code></pre>
</li>
</ol>
<span id="more"></span>

<p>实现转账功能</p>
<ol>
<li><p>在持久层接口中添加根据名称找账户的方法</p>
</li>
<li><p>在持久层实现类中实现方法<br> public Account findAccountByName(String accountName) {<br> try {<br>     List<Account> accounts &#x3D; runner.query(“select * from account where name &#x3D; ?”,new BeanListHandler<Account>(Account.class),accountName);<br>     if(accounts &#x3D;&#x3D; null || accounts.size() &#x3D;&#x3D; 0){<br>         return null;<br>     }else if(accounts.size() &gt; 1){<br>         throw new RuntimeException(“结果集不唯一,数据有问题”);<br>     }else{<br>         return accounts.get(0);<br>     }<br><br> } catch (Exception e) {<br>     throw new RuntimeException(e);<br> }<br> }</p>
</li>
<li><p>在业务层接口中添加转账方法</p>
</li>
<li><p>在业务层实现类中实现方法<br> public void transfer(String sourceName, String targetName, Double money) {<br> &#x2F;&#x2F;1. 根据名称查询转出账户<br> Account source &#x3D; accountDao.findAccountByName(sourceName);<br> &#x2F;&#x2F;2. 根据名称查询转入账户<br> Account target &#x3D; accountDao.findAccountByName(targetName);<br> &#x2F;&#x2F;3. 转出账户减钱<br> source.setBalance(source.getBalance()-money);<br> &#x2F;&#x2F;4. 转入账户加钱<br> target.setBalance(target.getBalance()+money);<br> &#x2F;&#x2F;5. 更新转出账户<br> accountDao.updateAccount(source);<br><br> &#x2F;&#x2F;int i&#x3D;1&#x2F;0<br><br> &#x2F;&#x2F;6. 更新转入账户<br> accountDao.updateAccount(target);<br> }</p>
</li>
</ol>
<p>问题：方法中没调用一次accountDao，就获取了一个连接，不同连接有自己的事务。如果中间报错，转账不完整。<br>需要使用ThreadLocal对象把Connection和当前线程绑定，从而使一个线程中只有一个能控制事务的对象</p>
<p>事务控制应该都是在业务层</p>
<ol>
<li>添加连接池工具类<br>package com.sqtian.utils;</li>
</ol>
<p>import javax.sql.DataSource;<br>import java.sql.Connection;</p>
<p>&#x2F;**</p>
<ul>
<li><p>连接工具类,用于从数据源中获取一个连接,并且实现线程的绑定<br> *&#x2F;<br>public class ConnectionUtils {<br> private ThreadLocal<Connection> tl &#x3D; new ThreadLocal<Connection>();<br> private DataSource datasource;</p>
<p> public void setDatasource(DataSource datasource) {<br> this.datasource &#x3D; datasource;<br> }</p>
<p> public Connection getThreadConnection(){<br> &#x2F;&#x2F;1. 先从ThreadLocal上获取<br> Connection connection &#x3D; tl.get();<br> try {<br>     &#x2F;&#x2F;2. 判断当前线程上是否有连接<br>     if(connection &#x3D;&#x3D; null){<br>         &#x2F;&#x2F;3. 从数据源中获取一个连接,并且存入ThreadLocal中<br>         connection &#x3D; datasource.getConnection();<br>         tl.set(connection);<br>     }<br>     &#x2F;&#x2F;4. 返回当前线程上的连接<br>     return connection;<br> } catch (Exception e) {<br>     throw new RuntimeException(e);<br> }<br> }</p>
<p> &#x2F;**</p>
<ul>
<li>把连接和线程解绑<br>  *&#x2F;<br> public void removeConnection(){<br> tl.remove();<br> }</li>
</ul>
</li>
</ul>
<h2 id=""><a href="#" class="headerlink" title="}"></a>}</h2><ol start="2">
<li>添加事务管理工具类</li>
</ol>
<p>package com.sqtian.utils;</p>
<p>import java.sql.SQLException;</p>
<p>&#x2F;**</p>
<ul>
<li><p>和事务管理相关的工具类,它包含了,开启事务,提交事务,回滚事务和释放连接<br> *&#x2F;<br>public class TransactionManager {</p>
<p> private ConnectionUtils connectionUtils;</p>
<p> public void setConnectionUtils(ConnectionUtils connectionUtils) {<br> this.connectionUtils &#x3D; connectionUtils;<br> }</p>
<p> &#x2F;**</p>
<ul>
<li>开启事务<br>  *&#x2F;<br> public void beginTransaction(){<br> try {<br> connectionUtils.getThreadConnection().setAutoCommit(false);<br> } catch (SQLException e) {<br> e.printStackTrace();<br> }<br> }</li>
</ul>
<p> &#x2F;**</p>
<ul>
<li>提交事务<br>  *&#x2F;<br> public void commit(){<br> try {<br> connectionUtils.getThreadConnection().commit();<br> } catch (SQLException e) {<br> e.printStackTrace();<br> }<br> }</li>
</ul>
<p> &#x2F;**</p>
<ul>
<li>回滚事务<br>  *&#x2F;<br> public void rollback(){<br> try {<br> connectionUtils.getThreadConnection().rollback();<br> } catch (SQLException e) {<br> e.printStackTrace();<br> }<br> }</li>
</ul>
<p> &#x2F;**</p>
<ul>
<li>释放连接<br>  *&#x2F;<br> public void release(){<br> try {<br> connectionUtils.getThreadConnection().close();&#x2F;&#x2F;换回连接池中<br> connectionUtils.removeConnection();<br> } catch (SQLException e) {<br> e.printStackTrace();<br> }<br> }</li>
</ul>
</li>
</ul>
<p>}</p>
<hr>
<ol start="3">
<li>在业务层控制事务</li>
</ol>
<p>package com.sqtian.service.impl;</p>
<p>import com.sqtian.dao.IAccountDao;<br>import com.sqtian.domain.Account;<br>import com.sqtian.service.IAccountService;<br>import com.sqtian.utils.TransactionManager;</p>
<p>import java.util.List;</p>
<p>&#x2F;**</p>
<ul>
<li><p>账户的业务层实现类</p>
</li>
<li></li>
<li><p>事务控制应该都是在业务层<br> *&#x2F;<br>public class AccountServiceImpl implements IAccountService {</p>
<p> private IAccountDao accountDao;<br> private TransactionManager txManager;</p>
<p> &#x2F;&#x2F;交给spring注入<br> public void setTxManager(TransactionManager txManager) {<br> this.txManager &#x3D; txManager;<br> }</p>
<p> &#x2F;&#x2F;交给spring注入<br> public void setAccountDao(IAccountDao accountDao) {<br> this.accountDao &#x3D; accountDao;<br> }</p>
<p> public void transfer(String sourceName, String targetName, Double money) {<br> try{<br>     &#x2F;&#x2F;1. 开启事务<br>     txManager.beginTransaction();<br>     &#x2F;&#x2F;2. 执行操作<br><br><br>     &#x2F;&#x2F;2.1. 根据名称查询转出账户<br>     Account source &#x3D; accountDao.findAccountByName(sourceName);<br>     &#x2F;&#x2F;2.2. 根据名称查询转入账户<br>     Account target &#x3D; accountDao.findAccountByName(targetName);<br>     &#x2F;&#x2F;2.3. 转出账户减钱<br>     source.setBalance(source.getBalance()-money);<br>     &#x2F;&#x2F;2.4. 转入账户加钱<br>     target.setBalance(target.getBalance()+money);<br>     &#x2F;&#x2F;2.5. 更新转出账户<br>     accountDao.updateAccount(source);<br>     &#x2F;&#x2F;2.6. 更新转入账户<br>     accountDao.updateAccount(target);<br><br><br>     &#x2F;&#x2F;3. 提交事务<br>     txManager.commit();<br><br> }catch (Exception e){<br>     &#x2F;&#x2F;5. 回滚操作<br>     txManager.rollback();<br>     throw new RuntimeException(e);<br> }finally {<br>     &#x2F;&#x2F;6. 释放连接<br>     txManager.release();<br> }<br> }</p>
</li>
</ul>
<p>}</p>
<hr>
<ol start="4">
<li><p>持久层实现类改变连接方式<br> &#x2F;&#x2F;不再希望通过queryRunner里取连接,而是通过connectionUtils取<br> &#x2F;&#x2F;删去原来的注入<constructor-arg name="ds" ref="dataSource"></constructor-arg></p>
<p> private ConnectionUtils connectionUtils;</p>
<p> public void setConnectionUtils(ConnectionUtils connectionUtils) {<br> this.connectionUtils &#x3D; connectionUtils;<br> }</p>
<p> &#x2F;&#x2F;改成加入connectionUtils.getThreadConnection()参数的guery方法<br> public Account findAccountByName(String accountName) {<br> try {<br>     List<Account> accounts &#x3D; runner.query(connectionUtils.getThreadConnection(),”select * from account where name &#x3D; ?”,new BeanListHandler<Account>(Account.class),accountName);<br>     if(accounts &#x3D;&#x3D; null || accounts.size() &#x3D;&#x3D; 0){<br>         return null;<br>     }else if(accounts.size() &gt; 1){<br>         throw new RuntimeException(“结果集不唯一,数据有问题”);<br>     }else{<br>         return accounts.get(0);<br>     }<br><br> } catch (Exception e) {<br>     throw new RuntimeException(e);<br> }<br> }</p>
</li>
</ol>
<hr>
<ol start="5">
<li>注入新的依赖<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
 https://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="accountService" class="com.sqtian.service.impl.AccountServiceImpl">
     <!--注入dao对象-->
     <property name="accountDao" ref="accountDao"></property>
     <!--注入事务管理器-->
     <property name="txManager" ref="txManager"></property>
 </bean>

 <bean id="accountDao" class="com.sqtian.dao.impl.AccountDaoImpl">
     <property name="runner" ref="runner"></property>
     <property name="connectionUtils" ref="connectionUtils"></property>
 </bean>

 <!--配置QueryRunner,如果用单例时,一个要用,另一个可能还没用完,线程受到影响.因此要用多例-->
 <bean id="runner" class="org.apache.commons.dbutils.QueryRunner" scope="prototype">
     <!--注入数据源-->

 </bean>

 <!--配置数据源连接池-->
 <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
     <!--配置连接数据库的必备信息-->
     <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
     <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/lovelycc?characterEncoding=utf8"></property>
     <property name="user" value="root"></property>
     <property name="password" value="root"></property>
 </bean>

 <!--配置Connection的工具类 ConnectionUtils-->
 <bean id="connectionUtils" class="com.sqtian.utils.ConnectionUtils">
     <!--注入数据源-->
     <property name="dataSource" ref="dataSource"></property>
 </bean>

 <!--配置事务管理器-->
 <bean id="txManager" class="com.sqtian.utils.TransactionManager">
     <property name="connectionUtils" ref="connectionUtils"></property>
 </bean></li>
</ol>
</beans>

<hr>
<h2 id="动态代理"><a href="#动态代理" class="headerlink" title="动态代理"></a>动态代理</h2><p>现在依赖太繁杂，方法之间也存在依赖。如果一个方法名改变了，则需要变动大量代码。<br>需要使用动态代理<br>类似于客户与生产厂家之间的代理商</p>
<p>基于接口的动态代理<br>1.<br>package com.sqtian.proxy;</p>
<p>&#x2F;**</p>
<ul>
<li><p>对生产厂家要求的接口<br> *&#x2F;<br>public interface IProducer {</p>
<p> &#x2F;**</p>
<ul>
<li>销售</li>
<li>@param money<br>  <em>&#x2F;<br> public void saleProduct(Double money);<br> &#x2F;</em>*</li>
<li>售后</li>
<li>@param money<br>  *&#x2F;<br> public void afterService(Double money);</li>
</ul>
</li>
</ul>
<h2 id="-1"><a href="#-1" class="headerlink" title="}"></a>}</h2><p>2.<br>package com.sqtian.proxy;</p>
<p>&#x2F;**</p>
<ul>
<li>一个生产者</li>
<li> *&#x2F;<br>public class Producer implements IProducer{  &#x2F;**<ul>
<li>销售</li>
<li>@param money<br>   *&#x2F;<br>  public void saleProduct(Double money){<br> System.out.println(“销售产品,并拿到钱:”+money);<br>  }</li>
</ul>
<p>  &#x2F;**</p>
<ul>
<li>售后</li>
<li>@param money<br>   *&#x2F;<br>  public void afterService(Double money){<br> System.out.println(“提供售后服务,并拿到钱:”+money);<br>  }</li>
</ul>
</li>
</ul>
<h2 id="-2"><a href="#-2" class="headerlink" title="}"></a>}</h2><p>package com.sqtian.proxy;</p>
<p>import java.lang.reflect.InvocationHandler;<br>import java.lang.reflect.Method;<br>import java.lang.reflect.Proxy;</p>
<p>&#x2F;**</p>
<ul>
<li>模拟一个消费者<br> <em>&#x2F;<br>public class Client {<br> public static void main(String[] args) {<br> &#x2F;&#x2F;匿名内部类访问外部成员时,外部成员要求是最终的<br> final Producer producer &#x3D; new Producer();<br><br> producer.saleProduct(10000d);<br><br> &#x2F;</em>*<br>  * 动态代理:<br>  * 	特点: 字节码随用随创建,随用随加载<br>  * 	作用: 不修改源码的基础上对方法加强<br>  * 	分类:<br>  * 		基于接口的动态代理<br>  * 		基于子类的动态代理<br>  * 	基于接口的动态代理:<br>  * 		涉及的类: Proxy<br>  * 		提供者: JDK官方<br>  * 	如何创建代理对象:<br>  * 		使用Proxy类中的newProxyInstance方法<br>  * 	创建代理对象的要求:<br>  * 		被代理类最少实现一个接口,如果没有则不能使用<br>  * 	newProxyInstance方法的参数:<br>  * 		ClassLoader: 类加载器<br>  * 			它用于加载代理对象字节码的.和被代理对象使用相同的类加载器. 固定写法 producer.getClass().getClassLoader()<br>  * 		Class[]<br>  * 			它是用于让代理对象和被代理对象有相同方法. 固定写法 producer.getClass().getInterfaces()<br>  * 		InvocationHandler: 用于提供增强的代码<br>  * 			它是让我们写如何代理.我们一般是都是些一个该接口的实现类.通常情况下都是匿名内部类.<br>  * 			此接口的实现类都是谁用谁写<br>  *<br>  *<br>  <em>&#x2F;<br> IProducer proxyProducer &#x3D; (IProducer) Proxy.newProxyInstance(producer.getClass().getClassLoader(), producer.getClass().getInterfaces(),<br>     new InvocationHandler() {<br>         &#x2F;</em>*<br>          * 作用: 执行被代理对象的任何接口方法都会经过该方法<br>          * @param proxy   代理对象的引用<br>          * @param method  当前执行的方法<br>          * @param args    当前执行方法所需的参数<br>          * @return        和被代理对象方法有相同的返回值<br>          * @throws Throwable<br>          <em>&#x2F;<br>     public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {<br>         &#x2F;&#x2F;提供增强的代码<br>         &#x2F;&#x2F;比如经销商提取20%利润<br><br>         Object returnValue &#x3D; null;<br>         &#x2F;&#x2F;1. 获取方法执行的参数<br>         Double money &#x3D; (Double) args[0];<br>         &#x2F;&#x2F;2. 判断当前方法是不是销售<br>         if(“saleProduct”.equals(method.getName())){<br>             returnValue &#x3D; method.invoke(producer,money</em>0.8d);<br>         }<br>         return returnValue;<br>     }<br> });<br><br> proxyProducer.saleProduct(10000d);<br> }</li>
</ul>
<h2 id="-3"><a href="#-3" class="headerlink" title="}"></a>}</h2><p>如果没有实现接口，则会报错</p>
<p>引出第二种代理方式<br>基于子类的动态代理<br>Producer 不需要实现接口</p>
<ol>
<li><p>导入cglib的jar包</p>
 <dependencies>
     <dependency>
         <groupId>cglib</groupId>
         <artifactId>cglib</artifactId>
         <version>2.1_3</version>
     </dependency>
 </dependencies>
 </li>
<li><p>&#x2F;**</p>
</li>
</ol>
<ul>
<li>模拟一个消费者<br> <em>&#x2F;<br>public class Client {<br> public static void main(String[] args) {<br> &#x2F;&#x2F;匿名内部类访问外部成员时,外部成员要求是最终的<br> final Producer producer &#x3D; new Producer();<br><br> producer.saleProduct(10000d);<br><br> &#x2F;</em>*<br>  * 动态代理:<br>  * 	特点: 字节码随用随创建,随用随加载<br>  * 	作用: 不修改源码的基础上对方法加强<br>  * 	分类:<br>  * 		基于接口的动态代理<br>  * 		基于子类的动态代理<br>  * 	基于接口的动态代理:<br>  * 		涉及的类: Enhancer<br>  * 		提供者: 第三方cglib库<br>  * 	如何创建代理对象:<br>  * 		使用Enhancer类中的create方法<br>  * 	创建代理对象的要求:<br>  * 		被代理类不能是最终类<br>  * 	create方法的参数:<br>  * 		Class: 字节码<br>  * 			它用于指定被代理对象的字节码<br>  * 		Callback: 用于提供增强的代码<br>  * 			它是让我们写如何代理.我们一般是都是些一个该接口的实现类.通常情况下都是匿名内部类.<br>  * 			此接口的实现类都是谁用谁写<br>  *			一般写的都是该接口的子接口实现类: MethodInterceptor<br>  *<br>  <em>&#x2F;<br> Producer cglibProducer &#x3D; (Producer) Enhancer.create(producer.getClass(),new MethodInterceptor(){<br>     &#x2F;</em>*<br>      * 作用: 执行被代理对象的任何接口方法都会经过该方法<br>      * @param proxy   代理对象的引用<br>      * @param method  当前执行的方法<br>      * @param args    当前执行方法所需的参数<br>      * @param methodProxy 当前执行方法的代理对象<br>      * @return        和被代理对象方法有相同的返回值<br>      * @throws Throwable<br>      <em>&#x2F;<br>     public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {<br><br>             &#x2F;&#x2F;提供增强的代码<br>             &#x2F;&#x2F;比如经销商提取20%利润<br><br>             Object returnValue &#x3D; null;<br>             &#x2F;&#x2F;1. 获取方法执行的参数<br>             Double money &#x3D; (Double) args[0];<br>             &#x2F;&#x2F;2. 判断当前方法是不是销售<br>             if(“saleProduct”.equals(method.getName())){<br>                 returnValue &#x3D; method.invoke(producer,money</em>0.8d);<br>             }<br>             return returnValue;<br>     }<br> });<br><br> cglibProducer.saleProduct(10000d);<br> }</li>
</ul>
<h2 id="-4"><a href="#-4" class="headerlink" title="}"></a>}</h2><p>回到转账案例<br>AccountServiceImpl中太多事务管理的冗余代码，通过代理对象统一管理</p>
<ol>
<li>把事务管理的代码交给BeanFactory<br>package com.sqtian.service.impl;</li>
</ol>
<p>&#x2F;**</p>
<ul>
<li><p>账户的业务层实现类</p>
</li>
<li></li>
<li><p>事务控制应该都是在业务层<br> *&#x2F;<br>public class AccountServiceImpl implements IAccountService {</p>
<p> private IAccountDao accountDao;</p>
<p> &#x2F;&#x2F;交给spring注入<br> public void setAccountDao(IAccountDao accountDao) {<br> this.accountDao &#x3D; accountDao;<br> }<br> public void transfer(String sourceName, String targetName, Double money) {<br> &#x2F;&#x2F;2.1. 根据名称查询转出账户<br> Account source &#x3D; accountDao.findAccountByName(sourceName);<br> &#x2F;&#x2F;2.2. 根据名称查询转入账户<br> Account target &#x3D; accountDao.findAccountByName(targetName);<br> &#x2F;&#x2F;2.3. 转出账户减钱<br> source.setBalance(source.getBalance()-money);<br> &#x2F;&#x2F;2.4. 转入账户加钱<br> target.setBalance(target.getBalance()+money);<br> &#x2F;&#x2F;2.5. 更新转出账户<br> accountDao.updateAccount(source);<br> &#x2F;&#x2F;2.6. 更新转入账户<br> accountDao.updateAccount(target);<br><br> System.out.println(“转账成功”);<br> }</p>
</li>
</ul>
<p>}</p>
<hr>
<p>package com.sqtian.factory;</p>
<p>import com.sqtian.service.IAccountService;<br>import com.sqtian.utils.TransactionManager;</p>
<p>import java.lang.reflect.InvocationHandler;<br>import java.lang.reflect.Method;<br>import java.lang.reflect.Proxy;</p>
<p>&#x2F;**</p>
<ul>
<li>用于创建Service的代理对象的工厂</li>
<li> *&#x2F;<br>public class BeanFactory {<br>  private IAccountService accountService;<br>  private TransactionManager txManager;  &#x2F;&#x2F;交给spring注入<br>  public void setTxManager(TransactionManager txManager) {<br>  this.txManager &#x3D; txManager;<br>  }  public final void setAccountService(IAccountService accountService) {<br>  this.accountService &#x3D; accountService;<br>  }  &#x2F;**<ul>
<li>获取Service代理对象<br>   <em>&#x2F;<br>  public IAccountService getAccountService() {<br> return (IAccountService) Proxy.newProxyInstance(accountService.getClass().getClassLoader(),<br> accountService.getClass().getInterfaces(),<br> new InvocationHandler() {<br>     &#x2F;</em>*<br>      * 添加事务支持<br>      *<br>      * @param proxy<br>      * @param method<br>      * @param args<br>      * @return<br>      * @throws Throwable<br>      *&#x2F;<br>     public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {<br>         Object returnValue &#x3D; null;<br>         try {<br>             &#x2F;&#x2F;1. 开启事务<br>             txManager.beginTransaction();<br>             &#x2F;&#x2F;2. 执行操作<br>             returnValue &#x3D; method.invoke(accountService, args);<br>             &#x2F;&#x2F;3. 提交事务<br>             txManager.commit();<br>             &#x2F;&#x2F;4. 返回结果<br>             return returnValue;<br>         } catch (Exception e) {<br>             &#x2F;&#x2F;5. 回滚操作<br>             txManager.rollback();<br>             throw new RuntimeException(e);<br>         } finally {<br>             &#x2F;&#x2F;6. 释放连接<br>             txManager.release();<br>         }<br>     }<br> });<br>  }</li>
</ul>
</li>
</ul>
<p>}</p>
<hr>
<ol start="2">
<li>修改配置文件<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
 https://www.springframework.org/schema/beans/spring-beans.xsd"> <!--配置代理的service-->
 <bean id="proxyAccountService" factory-bean="beanFactory" factory-method="getAccountService"></bean> <!--配置beanFactory-->
 <bean id="beanFactory" class="com.sqtian.factory.BeanFactory">
     <property name="accountService" ref="accountService"></property>
     <property name="txManager" ref="txManager"></property>
 </bean>



 <bean id="accountService" class="com.sqtian.service.impl.AccountServiceImpl">
     <!--注入dao对象-->
     <property name="accountDao" ref="accountDao"></property></li>
</ol>
<!--        &lt;!&ndash;注入事务管理器&ndash;&gt;-->
<!--        <property name="txManager" ref="txManager"></property>-->
<pre><code>&lt;/bean&gt;

&lt;bean id=&quot;accountDao&quot; class=&quot;com.sqtian.dao.impl.AccountDaoImpl&quot;&gt;
    &lt;property name=&quot;runner&quot; ref=&quot;runner&quot;&gt;&lt;/property&gt;
    &lt;property name=&quot;connectionUtils&quot; ref=&quot;connectionUtils&quot;&gt;&lt;/property&gt;
&lt;/bean&gt;

&lt;!--配置QueryRunner,如果用单例时,一个要用,另一个可能还没用完,线程受到影响.因此要用多例--&gt;
&lt;bean id=&quot;runner&quot; class=&quot;org.apache.commons.dbutils.QueryRunner&quot; scope=&quot;prototype&quot;&gt;
    &lt;!--注入数据源--&gt;

&lt;/bean&gt;

&lt;!--配置数据源连接池--&gt;
&lt;bean id=&quot;dataSource&quot; class=&quot;com.mchange.v2.c3p0.ComboPooledDataSource&quot;&gt;
    &lt;!--配置连接数据库的必备信息--&gt;
    &lt;property name=&quot;driverClass&quot; value=&quot;com.mysql.jdbc.Driver&quot;&gt;&lt;/property&gt;
    &lt;property name=&quot;jdbcUrl&quot; value=&quot;jdbc:mysql://localhost:3306/lovelycc?characterEncoding=utf8&quot;&gt;&lt;/property&gt;
    &lt;property name=&quot;user&quot; value=&quot;root&quot;&gt;&lt;/property&gt;
    &lt;property name=&quot;password&quot; value=&quot;root&quot;&gt;&lt;/property&gt;
&lt;/bean&gt;

&lt;!--配置Connection的工具类 ConnectionUtils--&gt;
&lt;bean id=&quot;connectionUtils&quot; class=&quot;com.sqtian.utils.ConnectionUtils&quot;&gt;
    &lt;!--注入数据源--&gt;
    &lt;property name=&quot;dataSource&quot; ref=&quot;dataSource&quot;&gt;&lt;/property&gt;
&lt;/bean&gt;

&lt;!--配置事务管理器--&gt;
&lt;bean id=&quot;txManager&quot; class=&quot;com.sqtian.utils.TransactionManager&quot;&gt;
    &lt;property name=&quot;connectionUtils&quot; ref=&quot;connectionUtils&quot;&gt;&lt;/property&gt;
&lt;/bean&gt;
</code></pre>
</beans>

<hr>
<h2 id="AOP的概念"><a href="#AOP的概念" class="headerlink" title="AOP的概念"></a>AOP的概念</h2><p>Aspect Oriented Programming 面向切面编程<br>通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术<br>利用AOP可以对业务逻辑的各个部分进行隔离，从而使得业务逻辑各部分之间的耦合度降低，提高程序的可重用性<br>优势：<br>    减少重复代码<br>    提高开发效率<br>    维护方便</p>
<p>相关术语<br>Joinpoint(连接点):<br>    所谓连接点是指那些被拦截的点.在spring中,这些点指方法,因为spring只支持方法类型的连接点<br>Pointcut(切入点):<br>    指我们要对哪些Joinpoint进行拦截的定义 (被动态代理的方法)</p>
<p>Advice(通知&#x2F;增强):<br>    拦截后要做的事情<br>    前置通知,后置通知,异常通知,最终通知,环绕通知</p>
<p>Target(目标对象):<br>    代理的目标对象</p>
<p>Weaving(织入):<br>    把增强应用到目标对象来创建新的代理对象的过程</p>
<p>Proxy(代理):<br>    被增强后产生的结果代理类</p>
<p>Aspect(切面):<br>    是切入点与通知的结合</p>
<p>打印日志的AOP测试</p>
<p>public class AccountServiceImpl implements IAccountService {<br>    public void saveAccount() {<br>        System.out.println(“执行了保存”);<br>    }</p>
<pre><code>public void updateAccount(int i) &#123;
    System.out.println(&quot;执行了更新&quot;);
&#125;

public int deleteAccount() &#123;
    System.out.println(&quot;执行了删除&quot;);
    return 0;
&#125;
</code></pre>
<h2 id="-5"><a href="#-5" class="headerlink" title="}"></a>}</h2><p>package com.sqtian.utils;</p>
<p>&#x2F;**</p>
<ul>
<li>用于记录日志的工具类,它里面提供了公共的代码<br> *&#x2F;</li>
</ul>
<p>public class Logger {</p>
<pre><code>/**
 * 用于打印日志,计划让其在切入点方法执行之前执行(切入点方法就是业务层方法)
 *
 */

public void printLog()&#123;
    System.out.println(&quot;Logger类中的printLog方法开始记录日志&quot;);
&#125;
</code></pre>
<h2 id="-6"><a href="#-6" class="headerlink" title="}"></a>}</h2><?xml version="1.0" encoding="UTF-8"?>
<p><beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        https://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop
        https://www.springframework.org/schema/aop/spring-aop.xsd"></p>
<pre><code>&lt;!-- 配置spring的IOC, 把Service对象配置进来 --&gt;
&lt;bean id=&quot;accountService&quot; class=&quot;com.sqtian.service.impl.AccountServiceImpl&quot;&gt;
&lt;/bean&gt;

&lt;!-- spring中基于XML的AOP配置步骤
    1. 把通知的Bean也交给spring来管理
    2. 使用aop:config标签表明开始AOP的配置
    3. 使用aop:aspect标签表面配置切面
            id属性: 是给切面提供一个唯一标识
            ref属性: 是指定通知类的bean的ID
    4. 在aop:aspect标签的内部使用对应标签来配置通知的类型
            我们现在的示例是让printLog方法在切入点方法执行之前执行,所以是前置通知
            aop:before 表示配置前置通知
                method属性:用于指定Logger类中哪个方法是前置通知
                pointcut属性:用于指定切入点表达式,该表达式的含义指的是对业务层中哪些方法增强

        切入点表达式的写法:
            关键字: execution(表达式)
            表达式:
                访问修饰符  返回值  包名.类名.方法名(参数列表)
            标准写法:
                public void com.sqtian.service.impl.AccountServiceImpl.saveAccount()
            访问修饰符可以省略
                void com.sqtian.service.impl.AccountServiceImpl.saveAccount()
            返回值可以使用通配符表示任意返回值
                * com.sqtian.service.impl.AccountServiceImpl.saveAccount()    
            包名可以使用通配符表示任意包，但是有几级包就业写几个*
                * *.*.*.*.AccountServiceImpl.saveAccount()   
            包名可以使用..表示当前包及其子包
                * *..AccountServiceImpl.saveAccount()
            类名和方法名都可以使用*表示通配
                * *..*.*()
            参数列表:
                可以直接写数据类型:
                    基本类型直接写名称         int
                    引用类型写包名.类名的方式   java.lang.String
                    可以使用通配符表示任意类型,但是必须有参数 * *..*.*(*)
                    可以使用..表示有无参数均可              * *..*.*(..)
            全通配写法:
                * *..*.*(..)
                
            实际开发中,切入点表达式的通常写法:
                切到业务层实现类下的所有方法
                * com.sqtian.service.impl.*.*(..)

--&gt;

&lt;!--配置Logger类--&gt;
&lt;bean id=&quot;logger&quot; class=&quot;com.sqtian.utils.Logger&quot;&gt;&lt;/bean&gt;

&lt;!--配置AOP--&gt;
&lt;aop:config&gt;
    &lt;!--配置切面--&gt;
    &lt;aop:aspect id=&quot;logAdvice&quot; ref=&quot;logger&quot;&gt;
        &lt;!--配置通知的类型,并且建立通知方法和切入点方法的关联--&gt;
        &lt;aop:before method=&quot;printLog&quot; pointcut=&quot;execution(* com.sqtian.service.impl.*.*(..))&quot;&gt;&lt;/aop:before&gt;
    &lt;/aop:aspect&gt;
&lt;/aop:config&gt;
</code></pre>
</beans>

<hr>
<p>&#x2F;**</p>
<ul>
<li>测试AOP的配置<br> *&#x2F;<br>public class AOPTest {<br> public static void main(String[] args) {<br> &#x2F;&#x2F;1. 获取容器<br> ApplicationContext ac &#x3D; new ClassPathXmlApplicationContext(“bean.xml”);<br> &#x2F;&#x2F;2. 获取对象<br> IAccountService as &#x3D; (IAccountService) ac.getBean(“accountService”);<br> &#x2F;&#x2F;3. 执行方法<br> as.saveAccount();<br> }<br>}</li>
</ul>
<hr>
<p>通知的类型<br>package com.sqtian.utils;</p>
<p>import org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint;</p>
<p>&#x2F;**</p>
<ul>
<li>用于记录日志的工具类,它里面提供了公共的代码<br> *&#x2F;</li>
</ul>
<p>public class Logger {</p>
<pre><code>/**
 * 前置通知
 *
 */

public void beforePrintLog()&#123;
    System.out.println(&quot;Logger类中的前置通知方法开始记录日志&quot;);
&#125;

/**
 * 后置通知
 *
 */

public void afterReturningPrintLog()&#123;
    System.out.println(&quot;Logger类中的后置通知方法开始记录日志&quot;);
&#125;

/**
 * 异常通知
 *
 */

public void afterThrowingPrintLog()&#123;
    System.out.println(&quot;Logger类中的异常通知方法开始记录日志&quot;);
&#125;

/**
 * 最终通知
 *
 */

public void afterPrintLog()&#123;
    System.out.println(&quot;Logger类中的最终通知方法开始记录日志&quot;);
&#125;

/**
 * 环绕通知
 * 问题:
 * 		当我们配置类环绕通知之后,切入点方法没有执行,而通知方法执行了
 * 分析:
 * 		通过对比动态代理中的环绕通知代码,发现动态代理的环绕通知有明确的切入点方法调用,
 * 解决:
 * 	spring框架为我们提供了一个接口: ProceedingJoinPoint. 该接口有一个方法proceed(). 此方法就相当于明确调用切入点方法
 * 	该接口可以作为环绕通知的方法参数,在程序执行时,spring框架会提供实现类给我们使用
 *
 * 	spring中的环绕通知:
 * 		它是spring框架为我们提供的一种可以在代码中手动控制增强方法何时执行的方式. 写在哪就在什么位置执行
 */
public Object aroundPrintLog(MethodInvocationProceedingJoinPoint pjp)&#123;
    Object rtValue = null;

    try &#123;
        Object[] args = pjp.getArgs(); //得到方法执行所需的参数

        System.out.println(&quot;Logger类中的环绕通知方法开始记录日志&quot;);
        rtValue = pjp.proceed(); //明确调用业务层方法(切入点方法)

        System.out.println(&quot;Logger类中的环绕通知方法开始记录日志&quot;);

        return rtValue;
    &#125;catch (Throwable t)&#123;
        System.out.println(&quot;Logger类中的环绕通知方法开始记录日志&quot;);
        throw new RuntimeException(t);
    &#125;finally &#123;
        System.out.println(&quot;Logger类中的环绕通知方法开始记录日志&quot;);
    &#125;
&#125;
</code></pre>
<p>}</p>
<hr>
<?xml version="1.0" encoding="UTF-8"?>
<p><beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        https://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop
        https://www.springframework.org/schema/aop/spring-aop.xsd"></p>
<pre><code>&lt;!-- 配置spring的IOC, 把Service对象配置进来 --&gt;
&lt;bean id=&quot;accountService&quot; class=&quot;com.sqtian.service.impl.AccountServiceImpl&quot;&gt;
&lt;/bean&gt;

&lt;!--配置Logger类--&gt;
&lt;bean id=&quot;logger&quot; class=&quot;com.sqtian.utils.Logger&quot;&gt;&lt;/bean&gt;

&lt;!--配置AOP--&gt;
&lt;aop:config&gt;


    &lt;!--配置切入点表达式 id属性用于指定表达式的唯一标识. expression属性用于指定表达式内容
        此标签写在aop:aspect标签内部只能当前切面使用.
        它还可以写在aop:aspect的外卖,此时就变成了所有切面可用,但是按约束要求要放在切面配置之前
    --&gt;
    &lt;aop:pointcut id=&quot;pt1&quot; expression=&quot;execution(* com.sqtian.service.impl.*.*(..))&quot;/&gt;


    &lt;!--配置切面--&gt;
    &lt;aop:aspect id=&quot;logAdvice&quot; ref=&quot;logger&quot;&gt;
</code></pre>
<!--            &lt;!&ndash;配置前置通知的类型,在切入点方法执行之前执行&ndash;&gt;-->
<!--            <aop:before method="beforePrintLog" pointcut-ref="pt1"></aop:before>-->

<!--            &lt;!&ndash;配置后置通知的类型,在切入点方法正常执行之后执行,与异常通知只有一个执行&ndash;&gt;-->
<!--            <aop:after-returning method="afterReturningPrintLog" pointcut-ref="pt1"></aop:after-returning>-->

<!--            &lt;!&ndash;配置异常通知的类型,在切入点方法执行产生异常之后执行,与后置通知只有一个执行&ndash;&gt;-->
<!--            <aop:after-throwing method="afterThrowingPrintLog" pointcut-ref="pt1"></aop:after-throwing>-->

<!--            &lt;!&ndash;配置最终通知的类型,无论切入点方法是否正常执行都会在其后面执行&ndash;&gt;-->
<!--            <aop:after method="afterPrintLog" pointcut-ref="pt1"></aop:after>-->


<pre><code>        &lt;!--配置环绕通知--&gt;
        &lt;aop:around method=&quot;aroundPrintLog&quot; pointcut-ref=&quot;pt1&quot;&gt;&lt;/aop:around&gt;

    &lt;/aop:aspect&gt;
&lt;/aop:config&gt;
</code></pre>
</beans>

<hr>
<h2 id="注解AOP"><a href="#注解AOP" class="headerlink" title="注解AOP"></a>注解AOP</h2><p>bean.xml</p>
<?xml version="1.0" encoding="UTF-8"?>
<p><beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        https://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop
        https://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/context
        https://www.springframework.org/schema/context/spring-context.xsd"></p>
<pre><code>&lt;!--配置要扫描的包--&gt;
&lt;context:component-scan base-package=&quot;com.sqtian&quot;&gt;&lt;/context:component-scan&gt;

&lt;!--配置spring开启注解AOP的支持--&gt;
&lt;aop:aspectj-autoproxy&gt;&lt;/aop:aspectj-autoproxy&gt;
</code></pre>
</beans>

<hr>
<h2 id="Service-“accountService”-public-class-AccountServiceImpl-implements-IAccountService-…"><a href="#Service-“accountService”-public-class-AccountServiceImpl-implements-IAccountService-…" class="headerlink" title="@Service(“accountService”)public class AccountServiceImpl implements IAccountService {…}"></a>@Service(“accountService”)<br>public class AccountServiceImpl implements IAccountService {<br>…<br>}</h2><p>package com.sqtian.utils;</p>
<p>import org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint;</p>
<p>&#x2F;**</p>
<ul>
<li>用于记录日志的工具类,它里面提供了公共的代码<br> *&#x2F;</li>
</ul>
<p>@Component(“logger”)<br>@Aspect &#x2F;&#x2F;表示当前类是一个切面类<br>public class Logger {</p>
<pre><code>/**
 * 注解配置切入点表达式
 */
@Pointcut(&quot;execution(* com.sqtian.service.impl.*.*(..))&quot;)
private void pt1()&#123;&#125;

/**
 * 前置通知
 *
 */
@Before(&quot;pt1()&quot;)
public void beforePrintLog()&#123;
    System.out.println(&quot;Logger类中的前置通知方法开始记录日志&quot;);
&#125;

/**
 * 后置通知
 *
 */
@AfterReturning(&quot;pt1()&quot;)
public void afterReturningPrintLog()&#123;
    System.out.println(&quot;Logger类中的后置通知方法开始记录日志&quot;);
&#125;

/**
 * 异常通知
 *
 */
@AfterThrowing(&quot;pt1()&quot;)
public void afterThrowingPrintLog()&#123;
    System.out.println(&quot;Logger类中的异常通知方法开始记录日志&quot;);
&#125;

/**
 * 最终通知
 *
 */
@After(&quot;pt1()&quot;)
public void afterPrintLog()&#123;
    System.out.println(&quot;Logger类中的最终通知方法开始记录日志&quot;);
&#125;

/**
 * 环绕通知
 */

@Arround(&quot;pt1()&quot;)
public Object aroundPrintLog(MethodInvocationProceedingJoinPoint pjp)&#123;
    Object rtValue = null;

    try &#123;
        Object[] args = pjp.getArgs(); //得到方法执行所需的参数

        System.out.println(&quot;Logger类中的环绕通知方法开始记录日志&quot;);
        rtValue = pjp.proceed(); //明确调用业务层方法(切入点方法)

        System.out.println(&quot;Logger类中的环绕通知方法开始记录日志&quot;);

        return rtValue;
    &#125;catch (Throwable t)&#123;
        System.out.println(&quot;Logger类中的环绕通知方法开始记录日志&quot;);
        throw new RuntimeException(t);
    &#125;finally &#123;
        System.out.println(&quot;Logger类中的环绕通知方法开始记录日志&quot;);
    &#125;
&#125;
</code></pre>
<p>}</p>
<hr>
<p>&#x2F;&#x2F;不用xml的方式,在配置类加上注解@EnableAspectJAutoProxy</p>
<p>package config;</p>
<p>import org.springframework.context.annotation.*;</p>
<p>@Configuration<br>@ComponentScan(“com.sqtian”)<br>@EnableAspectJAutoProxy<br>@Import(JdbcConfig.class)<br>@PropertySource(“classpath:JdbcConfig.properties”)<br>public class SpringConfiguration {</p>
<pre><code>//用于写公共配置
</code></pre>
<p>}</p>

                
            </div>
            <hr/>

            

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        文章作者:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="/shiqing/about" rel="external nofollow noreferrer">ShiQing</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        文章链接:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://shiqing.gitee.io/shiqing/2020/06/29/java-kuang-jia/javanote-spring-day03/">https://shiqing.gitee.io/shiqing/2020/06/29/java-kuang-jia/javanote-spring-day03/</a>
                </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        版权声明:
                    </i>
                </span>
                <span class="reprint-info">
                    本博客所有文章除特別声明外，均采用
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    许可协议。转载请注明来源
                    <a href="/shiqing/about" target="_blank">ShiQing</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>复制成功，请遵循本文的转载规则</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">查看</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>



            <div class="tag_share" style="display: block;">
                <div class="post-meta__tag-list" style="display: inline-block;">
                    
                        <div class="article-tag">
                            
                                <a href="/shiqing/tags/Java%E6%A1%86%E6%9E%B6/">
                                    <span class="chip bg-color">Java框架</span>
                                </a>
                            
                        </div>
                    
                </div>
                <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                    <link rel="stylesheet" type="text/css" href="/shiqing/libs/share/css/share.min.css">
<div id="article-share">

    
    <div class="social-share" data-sites="twitter,facebook,google,qq,qzone,wechat,weibo,douban,linkedin" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="/shiqing/libs/share/js/social-share.min.js"></script>
    

    

</div>

                </div>
            </div>
            
                <style>
    #reward {
        margin: 40px 0;
        text-align: center;
    }

    #reward .reward-link {
        font-size: 1.4rem;
        line-height: 38px;
    }

    #reward .btn-floating:hover {
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    #rewardModal {
        width: 320px;
        height: 350px;
    }

    #rewardModal .reward-title {
        margin: 15px auto;
        padding-bottom: 5px;
    }

    #rewardModal .modal-content {
        padding: 10px;
    }

    #rewardModal .close {
        position: absolute;
        right: 15px;
        top: 15px;
        color: rgba(0, 0, 0, 0.5);
        font-size: 1.3rem;
        line-height: 20px;
        cursor: pointer;
    }

    #rewardModal .close:hover {
        color: #ef5350;
        transform: scale(1.3);
        -moz-transform:scale(1.3);
        -webkit-transform:scale(1.3);
        -o-transform:scale(1.3);
    }

    #rewardModal .reward-tabs {
        margin: 0 auto;
        width: 210px;
    }

    .reward-tabs .tabs {
        height: 38px;
        margin: 10px auto;
        padding-left: 0;
    }

    .reward-content ul {
        padding-left: 0 !important;
    }

    .reward-tabs .tabs .tab {
        height: 38px;
        line-height: 38px;
    }

    .reward-tabs .tab a {
        color: #fff;
        background-color: #ccc;
    }

    .reward-tabs .tab a:hover {
        background-color: #ccc;
        color: #fff;
    }

    .reward-tabs .wechat-tab .active {
        color: #fff !important;
        background-color: #22AB38 !important;
    }

    .reward-tabs .alipay-tab .active {
        color: #fff !important;
        background-color: #019FE8 !important;
    }

    .reward-tabs .reward-img {
        width: 210px;
        height: 210px;
    }
</style>

<div id="reward">
    <a href="#rewardModal" class="reward-link modal-trigger btn-floating btn-medium waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close modal-close"><i class="fas fa-times"></i></a>
            <h4 class="reward-title">你的赏识是我前进的动力</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <ul class="tabs row">
                        <li class="tab col s6 alipay-tab waves-effect waves-light"><a href="#alipay">支付宝</a></li>
                        <li class="tab col s6 wechat-tab waves-effect waves-light"><a href="#wechat">微 信</a></li>
                    </ul>
                    <div id="alipay">
                        <img src="/shiqing/medias/reward/alipay.jpg" class="reward-img" alt="支付宝打赏二维码">
                    </div>
                    <div id="wechat">
                        <img src="/shiqing/medias/reward/wechat.png" class="reward-img" alt="微信打赏二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.tabs').tabs();
    });
</script>

            
        </div>
    </div>

    

    

    

    

    

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/shiqing/2020/06/29/java-kuang-jia/javanote-spring-day04/">
                    <div class="card-image">
                        
                        
                        <img src="/shiqing/medias/featureimages/17.jpg" class="responsive-img" alt="JavaNote_Spring_Day04">
                        
                        <span class="card-title">JavaNote_Spring_Day04</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            day4spring中的JDBCTemlate以及Spring事务控制

spring中的JdbcTemplate JdbcTemplate的作用：     他就是用于和数据库交互的，实现对表的CRUD操作 如何创建该对象： 对象中的常用方
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2020-06-29
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/shiqing/categories/Java/" class="post-category">
                                    Java
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/shiqing/tags/Java%E6%A1%86%E6%9E%B6/">
                        <span class="chip bg-color">Java框架</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/shiqing/2020/06/29/java-kuang-jia/javanote-spring-day02/">
                    <div class="card-image">
                        
                        
                        <img src="/shiqing/medias/featureimages/15.jpg" class="responsive-img" alt="JavaNote_Spring_Day02">
                        
                        <span class="card-title">JavaNote_Spring_Day02</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            day2spring中基于注解的IOC和ioc的案例

spring中ioc的常用注解

案例使用xml方式和注解方式实现单表的CRUD操作 持久层技术选择：dbutils

改造基于注解的ioc案例，使用纯注解的方式实现 spring的一
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2020-06-29
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/shiqing/categories/Java/" class="post-category">
                                    Java
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/shiqing/tags/Java%E6%A1%86%E6%9E%B6/">
                        <span class="chip bg-color">Java框架</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>

</div>



<!-- 代码块功能依赖 -->
<script type="text/javascript" src="/shiqing/libs/codeBlock/codeBlockFuction.js"></script>

<!-- 代码语言 -->

<script type="text/javascript" src="/shiqing/libs/codeBlock/codeLang.js"></script>


<!-- 代码块复制 -->

<script type="text/javascript" src="/shiqing/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/shiqing/libs/codeBlock/codeShrink.js"></script>


    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget card" style="background-color: white;">
            <div class="toc-title"><i class="far fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fas fa-list-ul"></i>
    </a>
</div>


<script src="/shiqing/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            collapseDepth: Number('0'),
            headingSelector: 'h2, h3, h4'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h2, h3, h4').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).hide();
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).show();
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>

    

</main>




        <footer class="page-footer bg-color">
    
    <div class="container row center-align" style="margin-bottom: 0px !important;">
        <div class="col s12 m8 l8 copy-right">
            Copyright&nbsp;&copy;
            
                <span id="year">2019-2024</span>
            
            <span id="year">2019</span>
            <a href="/shiqing/about" target="_blank">ShiQing</a>
            |&nbsp;Powered by&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a>
            |&nbsp;Theme&nbsp;<a href="https://github.com/blinkfox/hexo-theme-matery" target="_blank">Matery</a>
            <br>
            
            
            
            
            
            
            <span id="busuanzi_container_site_pv">
                |&nbsp;<i class="far fa-eye"></i>&nbsp;总访问量:&nbsp;<span id="busuanzi_value_site_pv"
                    class="white-color"></span>&nbsp;次
            </span>
            
            
            <span id="busuanzi_container_site_uv">
                |&nbsp;<i class="fas fa-users"></i>&nbsp;总访问人数:&nbsp;<span id="busuanzi_value_site_uv"
                    class="white-color"></span>&nbsp;人
            </span>
            
            <br>
            
            <br>
            
        </div>
        <div class="col s12 m4 l4 social-link social-statis">
    <a href="https://github.com/blinkfox" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fab fa-github"></i>
    </a>



    <a href="mailto:2528393970@qq.com" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fas fa-envelope-open"></i>
    </a>



    <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=2528393970" class="tooltipped" target="_blank" data-tooltip="QQ联系我: 2528393970" data-position="top" data-delay="50">
        <i class="fab fa-qq"></i>
    </a>







    <a href="/shiqing/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
        <i class="fas fa-rss"></i>
    </a>

</div>
    </div>
</footer>

<div class="progress-bar"></div>


        <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script type="text/javascript">
$(function () {
    var searchFunc = function (path, search_id, content_id) {
        'use strict';
        $.ajax({
            url: path,
            dataType: "xml",
            success: function (xmlResponse) {
                // get the contents from search data
                var datas = $("entry", xmlResponse).map(function () {
                    return {
                        title: $("title", this).text(),
                        content: $("content", this).text(),
                        url: $("url", this).text()
                    };
                }).get();
                var $input = document.getElementById(search_id);
                var $resultContent = document.getElementById(content_id);
                $input.addEventListener('input', function () {
                    var str = '<ul class=\"search-result-list\">';
                    var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
                    $resultContent.innerHTML = "";
                    if (this.value.trim().length <= 0) {
                        return;
                    }
                    // perform local searching
                    datas.forEach(function (data) {
                        var isMatch = true;
                        var data_title = data.title.trim().toLowerCase();
                        var data_content = data.content.trim().replace(/<[^>]+>/g, "").toLowerCase();
                        var data_url = data.url;
                        data_url = data_url.indexOf('/') === 0 ? data.url : '/' + data_url;
                        var index_title = -1;
                        var index_content = -1;
                        var first_occur = -1;
                        // only match artiles with not empty titles and contents
                        if (data_title !== '' && data_content !== '') {
                            keywords.forEach(function (keyword, i) {
                                index_title = data_title.indexOf(keyword);
                                index_content = data_content.indexOf(keyword);
                                if (index_title < 0 && index_content < 0) {
                                    isMatch = false;
                                } else {
                                    if (index_content < 0) {
                                        index_content = 0;
                                    }
                                    if (i === 0) {
                                        first_occur = index_content;
                                    }
                                }
                            });
                        }
                        // show search results
                        if (isMatch) {
                            str += "<li><a href='" + data_url + "' class='search-result-title'>" + data_title + "</a>";
                            var content = data.content.trim().replace(/<[^>]+>/g, "");
                            if (first_occur >= 0) {
                                // cut out 100 characters
                                var start = first_occur - 20;
                                var end = first_occur + 80;
                                if (start < 0) {
                                    start = 0;
                                }
                                if (start === 0) {
                                    end = 100;
                                }
                                if (end > content.length) {
                                    end = content.length;
                                }
                                var match_content = content.substr(start, end);
                                // highlight all keywords
                                keywords.forEach(function (keyword) {
                                    var regS = new RegExp(keyword, "gi");
                                    match_content = match_content.replace(regS, "<em class=\"search-keyword\">" + keyword + "</em>");
                                });

                                str += "<p class=\"search-result\">" + match_content + "...</p>"
                            }
                            str += "</li>";
                        }
                    });
                    str += "</ul>";
                    $resultContent.innerHTML = str;
                });
            }
        });
    };

    searchFunc('/shiqing/search.xml', 'searchInput', 'searchResult');
});
</script>

        <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


        <script src="/shiqing/libs/materialize/materialize.min.js"></script>
        <script src="/shiqing/libs/masonry/masonry.pkgd.min.js"></script>
        <script src="/shiqing/libs/aos/aos.js"></script>
        <script src="/shiqing/libs/scrollprogress/scrollProgress.min.js"></script>
        <script src="/shiqing/libs/lightGallery/js/lightgallery-all.min.js"></script>
        <script src="/shiqing/js/matery.js"></script>

        <!-- Baidu Analytics -->

        <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

        
        <script src="/shiqing/libs/others/clicklove.js" async="async"></script>
        
        
        <script async src="/shiqing/libs/others/busuanzi.pure.mini.js"></script>
        

        <script type="text/javascript">
            var OriginTitile = document.title,
                st;
            document.addEventListener("visibilitychange", function () {
                document.hidden ? (document.title = "看不见我~看不见我~", clearTimeout(st)) : (document.title =
                    "(๑•̀ㅂ•́) ✧被发现了～", st = setTimeout(function () {
                        document.title = OriginTitile
                    }, 3e3))
            })
        </script>

        <!-- 背景樱花飘落特效 -->
        
            <script type="text/javascript">
                //只在桌面版网页启用特效
                var windowWidth = $(window).width();
                if (windowWidth > 768) {
                    document.write('<script type="text/javascript" src="/js/xuehuapiaoluo.js"><\/script>');
                }
            </script>
        

        

        


        
        

        

        

        
        <script src="/shiqing/libs/instantpage/instantpage.js" type="module"></script>
        

    </body>

</html>
